﻿@{
    ViewBag.Title = "存储";
    Layout = "~/Views/Shared/FrameWorkList.cshtml";
}

<body>
    <div class="functionHeader" style="width:100%;text-align:left;margin:0px;margin-top:0px; border-bottom:1px solid #CCC;">
        <div class="lsider">
            <div class="updowninput btn-group" style="margin-top:10px;">
                <input id="radio11" class="category" name="category" value="存储" checked="checked" type="radio"><label for="radio11" class="suffix">存储</label><br>
                <input id="radio12" class="category" name="category" value="档案" type="radio"><label for="radio12" class="suffix">档案</label>
            </div>
            <div class="updowninput" style="width:120px;height:20px;margin-left:10px;">
                <p>来料单位</p>
                <select id="txtqueryFSupplierNO" name="FSupplierNO" class="form-control">
                    <option value="">==请选择==</option>
                </select>
            </div>
            <div class="updowninput" style="width:120px;height:20px;margin-left:10px;">
                <p>零部件号</p>
                <input type="text" id="txtqueryFProductionNO" class="form-control required" />
                &nbsp;
            </div>
            <div class="updowninput" style="width:120px;height:20px;margin-left:10px;">
                <p>来料日期</p>
                <input type="text" id="txtqueryFCurDate" class="form-control required input-wdatepicker" onfocus="WdatePicker()" />
                &nbsp;
            </div>
            <div class="updowninput" style="width:120px;height:20px;margin-left:10px;">
                <p>凭证编号</p>
                <input type="text"id="txtqueryFVoucherNo" class="form-control required" />
                &nbsp;
            </div>
            <div class="updowninput" style="width:120px;height:20px;margin-left:10px;">
                <p>仓库库位</p>
                <input type="text" id="txtqueryFStoreSetNO" class="form-control required" />
                &nbsp;
            </div>
            <div class="updowninput" style="width:120px;height:20px;margin-left:10px;">
                <p>台账日期</p>
                <input type="text" id="txtqueryFAccountDate" class="form-control required input-wdatepicker" onfocus="WdatePicker({ dateFmt: 'yyyyMM', isShowToday: false, isShowClear: false });" />
            </div>
            <div class="btn-group" style="margin-top:12px;margin-left:10px;">
                &nbsp;
                <a id="btn_search" class="btn btn-primary center-block" onclick=""><span class="glyphicon glyphicon-search"></span>  &nbsp; 查询</a>
            </div>
        </div>

        <div class="rsider">
            <div class="btn-group btn-operration" style="float:right;margin-top:12px;">
                <a class="btn btn-primary center-block " onclick="$.reload()">   <span class="glyphicon glyphicon-refresh"> </span>&nbsp刷新</a>
                <a class="btn btn-primary center-block active" onclick="btn_Delete()"> <span class="glyphicon glyphicon-trash">   </span>&nbsp删除</a>
                <a class="btn btn-primary center-block active" onclick="btn_Save()"><span class="glyphicon glyphicon-plus">    </span>&nbsp入库</a>
                <a class="btn btn-primary center-block active" onclick="btn_operration_Edit()"><span class="glyphicon glyphicon-plus">    </span>&nbsp修改</a>
                <a class="btn btn-primary center-block export" onclick="btn_Print()">  <span class="glyphicon glyphicon-print">   </span>&nbsp打印</a> 
                <a class="btn btn-primary center-block active" onclick="btn_Excel()">  <span class="glyphicon glyphicon-download"></span>&nbsp导出</a>
               
            </div>
        </div>

        <div class="btn-group btn-edit-entity" style="float:left;margin-top:12px;display:none;">
            <a class="btn btn-primary center-block" onclick="btn_Edit();">   <span class="glyphicon ">    </span>修改</a>
            <a class="btn btn-primary center-block" onclick="btn_Cancel();"><span class="glyphicon ">   </span>关闭</a>
        </div>
    </div>

    <form id="form">
        <table id="eidt_entity" class="form" style="width:600px;display:none; margin:0 80px; text-align:left;">
            <tr>
                <th class="formTitle">零件编号</th>
                <td class="formValue" style="width:140px;">
                    <input id="txtFProductionNO" name="FProductionNO" readonly="readonly" class="form-control" type="text">
                </td>
                <th class="formTitle">仓库编号</th>
                <td class="formValue"  style="width:100px;">
                    <select id="txtFStoreNO" name="FStoreNO" onchange="storeNOChange();" style="width:100px;" class="form-control required">
                    </select>
                </td>
                <th class="formTitle">实际数量</th>
                <th class="formTitle">容器数量</th>
                <td class="formValue">
                    <input id="txtFContainerQuantity" name="FContainerQuantity" class="form-control" type="text">
                </td>
            </tr>
            <tr>
                <th class="formTitle">零件名称</th>
                <td class="formValue" style="width:140px;">
                    <input id="txtFProductionName" name="FProductionName" readonly="readonly" class="form-control" type="text">
                </td>
                <th class="formTitle">仓库库位</th>
                <td class="formValue"  style="width:100px;">
                    <select id="txtFStoreSetNO" name="FStoreSetNO" class="form-control required">
                    </select>
                </td>
                <td class="formValue">
                    <input id="txtFQuantity" name="FQuantity" onkeyup="valueChange()" class="form-control" type="text">
                </td>
                <th class="formTitle">托盘数量</th>
                <td class="formValue">
                    <input id="txtFPalletQuantity" name="FPalletQuantity"  class="form-control" type="text">
                </td>
            </tr>
        </table>
    </form>

    <div id="grid111">
        <table id="gridList1"></table>
        <div id="gridPager1"></div>
    </div>
    <div id="grid222" style="">
        <table id="gridList2"></table>
        <div id="gridPager2"></div>
    </div>
</body> 


<script>
    var rowData = {};
    var index = -1;
    var FAccountDate=@ViewBag.FAccountDate;
    $(function () {
        initControl();
        gridList1();
    });
    function initControl() {
        $('.category').on("click", function () {
            var aa = $("input[type='radio'].category:checked").val();
            if (aa == '存储') {
                gridList1();
            } else {
                gridList2();
            }});
       
            //来料单位
        $("#txtqueryFSupplierNO").bindSelect({
                url: "/BaseData/ZSJ_B1_GH_SI/GetGridJson",
                id: "UnitNO",
                text: "UnitNOShortName",
                search:true
            });

            //仓库编号
            $("#txtFStoreNO").bindSelect({  
                url: "/BaseData/CPK_ZD_11_DatStoreHouse/GetGridJson",
                id: "FStoreNO",
                text: "FStoreName",
                search: true
            });
            //库位定制
            $("#txtFStoreSetNO").bindSelect({
                url: "/BaseData/CPK_ZD_12_DatStoreHouseSet/StoreHouseSets?storeNO=" + $("#txtFStoreNO").val(),
                id: "FStoreSetNO",
                text: "FStoreSetNO",
                search:true
            });
            //台帐日期赋初值
            $("#txtqueryFAccountDate").val(FAccountDate);
    }

    function storeNOChange() {
        $("#txtFStoreSetNO").clearSelect();
        //库位定制
        $("#txtFStoreSetNO").bindSelect({
            url: "/BaseData/CPK_ZD_12_DatStoreHouseSet/StoreHouseSets?storeNO=" + $("#txtFStoreNO").val(),
            id: "FStoreSetNO",
            text: "FStoreSetNO",
            search: true
        });
    }

    function btn_Delete() {
        var postData = [];
        postData.push(rowData.FRegisterID);
        $.submitForm({
            url: "/WareHouse/EnterWareHouse/DeleteStoStorageCard",
            param: { datas: JSON.stringify(postData) },
            success: function () {
                $("#gridList1").resetSelection();
                $("#gridList1").trigger("reloadGrid");
            }
        })
    }

    function btn_Save() {
        var postData = [];

        $("#gridList1 input:checkbox:checked").each(function () {
            var rowid = $(this).attr("value");
            postData.push($("#gridList1").jqGrid('getRowData', rowid).FRegisterID);
        });
        $.submitForm({
            url: "/WareHouse/EnterWareHouse/SaveCC_StoStorageCard",
            param: { datas: JSON.stringify(postData) },
            success: function () {
                $("#gridList1").resetSelection();
                $("#gridList1").trigger("reloadGrid");
            }
        })
    }

    function btn_operration_Edit() {
        $.showOrHide($(".btn-operration"));
        $.showOrHide($("#eidt_entity"));
        $.showOrHide($(".btn-edit-entity"));
    }
    function valueChange() {
        var $FContainerQuantity = Math.ceil($("#txtFQuantity").val() / rowData["FFactContent"]);
        var $FPalletQuantity = Math.ceil($FContainerQuantity / rowData["FPalletFactContent"]);
        $("#txtFContainerQuantity").val($FContainerQuantity);
        $("#txtFPalletQuantity").val($FPalletQuantity);
        rowData["FContainerQuantity"] = $FContainerQuantity;
        rowData["FPalletQuantity"] = $FPalletQuantity;
    }

    function btn_Edit() {
        $.each(rowData, function (key, value) {
            if ($("#txt" + key).val()) {
                rowData[key] = $("#txt" + key).val();
            }
        });

        $.submitForm({
            url: "/WareHouse/EnterWareHouse/EditStoStorageCard",
            param: rowData,
            success: function () {
                $("#gridList1").resetSelection();
                $("#gridList1").trigger("reloadGrid");
            }
        })
    }

    function btn_Cancel() {

        $.showOrHide($(".btn-operration"));
        $.showOrHide($("#eidt_entity"));
        $.showOrHide($(".btn-edit-entity"));
        $.each(rowData, function (key, value) {
            rowData[key] = "";
        });
    }

    function gridList1() {
        $("#grid111").show();
        $("#grid222").hide();
        $(".rsider .active").show();
        var $gridList = $("#gridList1");
        $gridList.dataGridForJson({
            url: "/VBaseData/V_CPK_21_CC_StoStorageCard/GetGridJson",
            height: $(window).height() - 170,
            colModel: [
            { label: "id", name: "FStorageID", width: 120, align: 'center', hidden: true },
            { label: "FRegisterID", name: "FRegisterID", width: 120, align: 'center', hidden: true },
            { label: '<input id="selectAll" type="checkbox" style="text-align:center;">', width: 60, align: 'center', sortable: false, formatter: $.checkbox, unformat: $.empty },
            { label: "存储卡号", name: "FDouBarCode", width: 160, align: 'center' },
            { label: "来料单位", name: "FSupplierNO", width: 120, align: 'left' },
            { label: "来料单位名称", name: "FSupplierName", width: 120, align: 'left' },
            { label: '入库日期', name: 'FCurDate', width: 100, align: 'center' },
            { label: '零件编号', name: 'FProductionNO', width: 140, align: 'left' },
            { label: '零件名称', name: 'FProductionName', width: 140, align: 'left' },
            { label: '发生方式', name: 'FDocuTypeName', width: 80, align: 'center' },
            { label: '批次号', name: 'FVoucherNo', width: 80, align: 'center' },
            { label: '开票数量', name: 'FQuantity_KP', width: 80, align: 'right' },
            { label: '实际数量', name: 'FQuantity', width: 80, align: 'right' },
            { label: '仓库编号', name: 'FStoreNO', width: 80, align: 'left' },
            { label: '库位编号', name: 'FStoreSetNO', width: 80, align: 'left' },
            { label: '容器编号', name: 'FContainerNO', width: 80, align: 'left' },
            { label: '容器名称', name: 'FContainerName', width: 80, align: 'left' },
            { label: '容器数量', name: 'FContainerQuantity', width: 80, align: 'right' },
            { label: '实际装箱', name: 'FContent', width: 80, align: 'right' },
            { label: '标准装箱', name: 'FFactContent', width: 80, align: 'right' },
            { label: '托盘编号', name: 'FPalletNO', width: 80, align: 'left' },
            { label: '托盘数量', name: 'FPalletQuantity', width: 80, align: 'right' },
            { label: '实际容量', name: 'FPalletContent', width: 80, align: 'right' },
            { label: '标准容量', name: 'FPalletFactContent', width: 80, align: 'right' },
            { label: '凭证编号', name: 'FVoucherNo', width: 80, align: 'center' },
            { label: '备注', name: 'FDescription', width: 80, align: 'left' },
            { label: '供货单位', name: 'FProCompanyNO', width: 80, align: 'left' },
            { label: '供货单位名称', name: 'FProCompanyName', width: 120, align: 'left' },
            { label: '零件状态', name: 'FProductionTypeName', width: 60, align: 'left' },
            { label: '零件状态编号', name: 'FProductionTypeNO', width: 60, align: 'left', hidden: true },
            { label: '输入人员', name: 'FCreateBy', width: 80, align: 'left' },
            { label: '输入日期', name: 'FCreateDate', width: 80, align: 'center' },
            { label: '输入时间', name: 'FCreateTime', width: 60, align: 'center' }
            ],
            pager: "#gridPager1",
            sortname: 'FDouBarCode desc',
            viewrecords: true,
            onSelectRow: function (rowId) {
                rowData = $gridList.jqGrid('getRowData', rowId);
                index = rowId;
                $("#form").formSerialize(rowData, "txt");
            }
        });
        $("#btn_search").click(function () {
            query($gridList);
        });
        $("#selectAll").click(function (e) {
            $("input[name='checkbox']").prop("checked", this.checked);
            e.stopPropagation();
        });
    }

    function gridList2() {
        $("#grid111").hide();
        $("#grid222").show();
        $(".rsider .active").hide();
        var $gridList = $("#gridList2");
       
        var url="/VBaseData/V_CPK_22_CK_StoStorageCard_Mid/GetGridJson";
        var queryFAccountDate=$("#txtqueryFAccountDate").val();
        if( queryFAccountDate!=FAccountDate){
            url="/VBaseData/V_CPK_23_CK_StoStorageCard_Arc/GetGridJson";
        }
        $gridList.dataGrid({
            url: url,
            height: $(window).height() - 160,
            colModel: [
            { label: "id", name: "FStorageID", width: 120, align: 'center', hidden: true },
            { label: "FRegisterID", name: "FRegisterID", width: 120, align: 'center', hidden: true },
            { label: '<input id="selectAllMid" type="checkbox" style="text-align:center;">', width: 60, align: 'center', sortable: false, formatter: $.checkbox, unformat: $.empty },
            { label: "入库单号", name: "FDocuNO", width: 120, align: 'center' },
            { label: "存储卡号", name: "FDouBarCode", width: 120, align: 'center' },
            { label: "来料单位", name: "FProCompanyNO", width: 120, align: 'center' },
            { label: "来料单位名称", name: "FProCompanyName", width: 120, align: 'left' },
            { label: '入库日期', name: 'FCurDate', width: 100, align: 'center' },
            { label: '零件编号', name: 'FProductionNO', width: 115, align: 'center' },
            { label: '零件名称', name: 'FProductionName', width: 115, align: 'left' },
            { label: '发生方式', name: 'FDocuTypeName', width: 80, align: 'center' },
            { label: '批次号', name: 'FVoucherNo', width: 80, align: 'left' },
            { label: '开票数量', name: 'FQuantity_KP', width: 80, align: 'right' },
            { label: '实际数量', name: 'FQuantity', width: 80, align: 'right' },
            { label: '仓库编号', name: 'FStoreNO', width: 80, align: 'left' },
            { label: '库位编号', name: 'FStoreSetNO', width: 80, align: 'left' },
            { label: '容器编号', name: 'FContainerNO', width: 80, align: 'center' },
            { label: '容器名称', name: 'FContainerName', width: 80, align: 'left' },
            { label: '容器数量', name: 'FContainerQuantity', width: 80, align: 'right' },
            { label: '实际装箱', name: 'FContent', width: 80, align: 'right' },
            { label: '标准装箱', name: 'FFactContent', width: 80, align: 'right' },
            { label: '托盘编号', name: 'FPalletNO', width: 80, align: 'center' },
            { label: '托盘数量', name: 'FPalletQuantity', width: 80, align: 'right' },
            { label: '实际容量', name: 'FPalletContent', width: 80, align: 'right' },
            { label: '标准容量', name: 'FPalletFactContent', width: 80, align: 'right' },
            { label: '凭证编号', name: 'FVoucherNo', width: 80, align: 'center' },
            { label: '备注', name: 'FDescription', width: 80, align: 'center' },
            { label: '供货单位', name: 'FProCompanyNO', width: 80, align: 'center' },
            { label: '供货单位名称', name: 'FProCompanyName', width: 120, align: 'left' },
            { label: '零件状态', name: 'FProductionTypeName', width: 60, align: 'left' },
            { label: '零件状态编号', name: 'FProductionTypeNO', width: 60, align: 'left', hidden: true },
            { label: '输入人员', name: 'FCreateBy', width: 80, align: 'center' },
            { label: '输入日期', name: 'FCreateDate', width: 80, align: 'center' },
            { label: '输入时间', name: 'FCreateTime', width: 80, align: 'center' },
            ],
            pager: "#gridPager2",
            sortname: 'FDouBarCode desc',
            postData:{FAccountDate:queryFAccountDate},
            viewrecords: true,
            rownumWidth:40
        });
        $("#btn_search").click(function () {
            query($gridList);
        });
        $("#selectAllMid").click(function (e) {
            $("input[name='checkbox']").prop("checked", this.checked);
            e.stopPropagation();
        });
    }

    function query(obj) {
        var aa = $("input[type='radio'].category:checked").val();
        if(aa=="档案"){
            gridList2();
        }
        var FTypeNO = "";
        if ($("#txtFTypeNO").val() != "") {
            FTypeNO = $("#txtFTypeNO").val();
        }
        obj.jqGrid('setGridParam', {
            postData: { type: FTypeNO, FSupplierNO: $("#txtqueryFSupplierNO").val(), FProductionNO: $("#txtqueryFProductionNO").val(), FCurDate: $("#txtqueryFCurDate").val(), FAccountDate: $("#txtqueryFAccountDate").val(), FVoucherNo: $("#txtqueryFVoucherNo").val(), FStoreSetNO: $("#txtqueryFStoreSetNO").val() }
        }).trigger('reloadGrid');
    }

    //打印存储卡
    function btn_Print() {
        var dataArray = [];
        var flag = "reg";
        var aa = $("input[type='radio'].category:checked").val();
        if (aa == '存储') {
            $("#gridList1 input:checkbox:checked").each(function () {
                var rowid = $(this).attr("value");
                dataArray.push($("#gridList1").jqGrid('getRowData', rowid).FRegisterID);
            });
        } else {
            $("#gridList2 input:checkbox:checked").each(function () {
                var rowid = $(this).attr("value");
                dataArray.push($("#gridList2").jqGrid('getRowData', rowid).FRegisterID);
            });
            flag = "arc";//档案
        };
        if (dataArray.length<=0) {
            $.modalMsg("请选择打印数据", "error");
            return false;
        }
        $.detailOpen({
            id: "PrintStorgeCard",
            title: "",
            url: "/WareHouse/EnterWareHouse/PrintStorgeCard?flag=" + flag + "&data=" + dataArray.join(',')
        });
    }
</script>